<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="assets/css/bootstrap.css" rel="stylesheet"/>
    <link rel="stylesheet" href="css/style.css"/>
    <link href="assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/ace.min.css"/>
    <link rel="stylesheet" href="font/css/font-awesome.min.css"/>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="assets/layer/layer.js" type="text/javascript"></script>
    <script src="assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/typeahead-bs2.min.js"></script>
    <!--    <script src="assets/js/jquery.dataTables.min.js"></script>-->
    <!--    <script src="assets/js/jquery.dataTables.bootstrap.js"></script>-->
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
    <title>个人信息管理</title>
</head>

<body>

<div class="clearfix">
    <div class="admin_info_style">
        <!---------------------------------------------管理员个人信息------------------------------>
        <div id="app">
            <div class="admin_modify_style" id="Personal">
                <div class="type_title">管理员信息</div>
                <div class="xinxi">
                    <!---------------------------------------------以下内容从数据库调取数据--开始---------------------------->
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">头像: </label>
                        <img  id="pro" :src="imgdata" height="50px"/>
                        <a href="javascript:;"  class="btn btn-warning btn-xs" @click="show" style="margin-left: 87px">更换头像</a>
                    </div>
                    <div class="form-group" v-if="showUpload">
                        <input type="file" name="file" @change="loadFile($event)" />
                        <button @click="upload" class="btn btn-warning btn-xs">确认更换</button>
                        <button @click="close" class="btn btn-warning btn-xs">关闭</button>
                    </div>




                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">用户名： </label>
                        <div class="col-sm-9">
                            <input type="text" name="用户名" v-model="adminInfo.name" class="col-xs-7 text_info"
                                   disabled="disabled">
                            <!---------------------------------------------以下内容从数据库调取数据--结束---------------------------->
                            &nbsp;&nbsp;&nbsp;

                            <a href="javascript:;" onclick="change_Password()" class="btn btn-warning btn-xs">修改密码</a>
                        </div>
                    </div>

                    <!---------------------------------------------以下内容从数据库调取数据--开始---------------------------->

                    <div class="form-group"><label class="col-sm-3 control-label no-padding-right">账号： </label>
                        <div class="col-sm-9"><input type="text"  v-model="adminInfo.userName"
                                                     class="col-xs-7 text_info"
                                                     disabled="disabled"></div>
                    </div>
                    <div class="form-group"><label class="col-sm-3 control-label no-padding-right">移动电话： </label>
                        <div class="col-sm-9"><input type="text" name="移动电话" v-model="adminInfo.phone"
                                                     class="col-xs-7 text_info"
                                                     disabled="disabled"></div>
                    </div>
                    <div class="form-group"><label class="col-sm-3 control-label no-padding-right">权限： </label>
                        <div class="col-sm-9"><span>{{adminInfo.adminType.title}}</span></div>
                    </div>
                    <div class="form-group"><label class="col-sm-3 control-label no-padding-right">管辖区域： </label>
                        <div class="col-sm-9"><span>无</span></div>
                    </div>
                    <div class="form-group"><label class="col-sm-3 control-label no-padding-right">注册时间： </label>
                        <div class="col-sm-9"><span>{{adminInfo.inputTime.substring(0,10)}}</span></div>
                    </div>
                    <!---------------------------------------------以下内容从数据库调取数据--结束---------------------------->


                    <div class="Button_operation clearfix">
                        <button onclick="modify();" class="btn btn-danger radius" type="submit">修改信息</button>
                        <button onclick="save_info();" @click="save" class="btn btn-success radius" type="button">保存修改</button>
                    </div>
                </div>
            </div>
        </div>
        <!---------------------------------------------管理员登录记录------------------------------>
        <div id="app2">
            <div class="recording_style">
                <div class="type_title">管理员登陆记录</div>
                <div class="recording_list">
                    <table class="table table-border table-bordered table-bg table-hover table-sort" id="sample-table">
                        <thead>
                        <tr class="text-c">
                            <th width="25"><label><input type="checkbox" class="ace"><span class="lbl"></span></label>
                            </th>
                            <th width="80">ID</th>
                            <th>内容</th>
                            <th width="10%">用户名</th>
                            <th width="120">客户端IP</th>
                            <th width="150">时间</th>
                        </tr>
                        </thead>

                        <!---------------------------------------------以<tbody>为单位循环--------------------------->
                        <tbody>
                        <tr role="row" class="odd" v-for="record in adminLoginRecords.list">
                            <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                            <td>{{record.adminId}}</td>
                            <td>登录成功!</td>
                            <td>admin</td>
                            <td>{{record.ip}}</td>
                            <td>{{record.inputTime.substring(0,10)+" "+record.inputTime.substring(11,16)}}</td>
                        </tr>
                        </tbody>
                    </table>

                </div>

                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table_info" role="status" aria-live="polite">
                            第{{adminLoginRecords.pageNum}}/{{adminLoginRecords.pages}} 页，共 {{adminLoginRecords.total}} 条
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap" id="sample-table_paginate">
                            <ul class="pagination">
                                <li :class="{'disabled':adminLoginRecords.pageNum==1}">
                                    <a href="#" @click="initRecord(adminLoginRecords.prePage)">上一页</a>
                                </li>

                                <li v-for="i in adminLoginRecords.pages" @click.prevent="initRecord(i)"
                                    :class="{'active':adminLoginRecords.pageNum==i}">
                                    <a href="#"> {{i}}</a>
                                </li>

                                <li :class="{'disabled':adminLoginRecords.pageNum==adminLoginRecords.pages}">
                                    <a href="#" @click="initRecord(adminLoginRecords.nextPage)">下一页</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--修改密码样式-->
    <div class="change_Pass_style" id="change_Pass">
        <ul class="xg_style">
            <li><label class="label_name">原&nbsp;&nbsp;密&nbsp;码</label><input name="原密码" type="password" class=""
                                                                              id="password"></li>
            <li><label class="label_name">新&nbsp;&nbsp;密&nbsp;码</label><input name="新密码" type="password" class=""
                                                                              id="Nes_pas"></li>
            <li><label class="label_name">确认密码</label><input name="再次确认密码" type="password" class="" id="c_mew_pas">
            </li>

        </ul>
    </div>

</div>
</body>
</html>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            path:'http://localhost:8080/',
            adminInfo: {
                id: 1,
                profile:'',
            },
            file:'',
            showUpload:false,
            imgdata:'',
            //adminLoginRecords:[],
        },
        created: function () {
            this.initData();
            //this.initRecord();
        },
        methods: {
            initData: function () {
               //var i= localStorage.getItem("admin").anchor("adminId");
               //console.log(i);
                axios.get("http://localhost:8080/manage/adminInfo?id=1").then(
                    res => {
                        this.adminInfo = res.data.data;
                        console.log(this.adminInfo);
                        console.log(this.adminInfo.profile);
                        this.imgdata=this.path+'adminImages/'+this.adminInfo.profile;
                    }
                );
            },
            save:function () {
                console.log(this.adminInfo);
                axios.post("http://localhost:8080/manage/updateAdminInfo",this.adminInfo).then(
                    res=>{
                        console.log(res.data.message);
                    }
                );
            },
            show:function () {
                this.showUpload=true;
            },
            close:function () {
                this.showUpload=false;
                this.file='';
                this.imgdata=this.path+'adminImages/'+this.adminInfo.profile;
            },
            //预览图片
            loadFile: function(event) {
                //获得网页中的第一个图片信息
                this.file = event.target.files[0];
                console.log(this.file);
                var fileReader = new FileReader();
                fileReader.onload =
                    e => {
                    //将图片转为base64格式
                        var base64 = e.target.result;
                        this.imgdata = base64;
                    }
                    //加载图片 实现预览
                fileReader.readAsDataURL(this.file);
            },
            upload: function() {
                //创建一个FormData对象
                var formData = new FormData();
                //将上传的文件添加到formdata中
                formData.append('file', this.file);
                axios.post("http://localhost:8080/manage/upload?id="+this.adminInfo.id, formData, {
                    headers: {
                        //指定文件类型
                        'Content-Type': 'multipart/form-data'
                    }
                }).then(function(response) {
                    // 请求成功
                    console.log("更换头像成功");
                    console.log(response.data)
                }, function(err) {
                    console.log("更换头像失败")
                });
                this.showUpload=false;
                //this.initData();
            },
        }
    });
</script>
<script>
    var app2=new Vue({
        el:'#app2',
        data:{
            adminLoginRecords:{},
        },
        created:function () {
            this.initRecord(1);
        },
        methods: {
            initRecord:function (pageNum) {
                axios.get("http://localhost:8080/manage/adminLoginRecord?id=1&pageNum="+pageNum).then(res => {
                    console.log("------");
                    console.log(res.data);

                    this.adminLoginRecords = res.data.data;
                });
            },
        }
    })
</script>
<script>
    //按钮点击事件
    function modify() {
        $('.text_info').attr("disabled", false);
        $('.text_info').addClass("add");
        $('#Personal').find('.xinxi').addClass("hover");
        $('#Personal').find('.btn-success').css({'display': 'block'});
    };

    function save_info() {
        var num = 0;
        var str = "";
        $(".xinxi input[type$='text']").each(function (n) {
            if ($(this).val() == "") {

                layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                    title: '提示框',
                    icon: 0,
                });
                num++;
                return false;
            }
        });
        if (num > 0) {
            return false;
        } else {

            layer.alert('修改成功！', {
                title: '提示框',
                icon: 1,
            });
            $('#Personal').find('.xinxi').removeClass("hover");
            $('#Personal').find('.text_info').removeClass("add").attr("disabled", true);
            $('#Personal').find('.btn-success').css({'display': 'none'});
            layer.close();

        }
    };
    //初始化宽度、高度
    $(".admin_modify_style").height($(window).height());
    $(".recording_style").width($(window).width() - 400);
    //当文档窗口发生改变时 触发  
    $(window).resize(function () {
        $(".admin_modify_style").height($(window).height());
        $(".recording_style").width($(window).width() - 400);
    });

    //修改密码
    function change_Password() {
        layer.open({
            type: 1,
            title: '修改密码',
            area: ['300px', '300px'],
            shadeClose: true,
            content: $('#change_Pass'),
            btn: ['确认修改'],
            yes: function (index, layero) {
                if ($("#password").val() == "") {
                    layer.alert('原密码不能为空!', {
                        title: '提示框',
                        icon: 0,

                    });
                    return false;
                }
                if ($("#Nes_pas").val() == "") {
                    layer.alert('新密码不能为空!', {
                        title: '提示框',
                        icon: 0,

                    });
                    return false;
                }

                if ($("#c_mew_pas").val() == "") {
                    layer.alert('确认新密码不能为空!', {
                        title: '提示框',
                        icon: 0,

                    });
                    return false;
                }
                if (!$("#c_mew_pas").val || $("#c_mew_pas").val() != $("#Nes_pas").val()) {
                    layer.alert('密码不一致!', {
                        title: '提示框',
                        icon: 0,

                    });
                    return false;
                } else {
                    layer.alert('修改成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close();
                }
            }
        });
    }
</script>
<script>
    jQuery(function ($) {
        var oTable1 = $('#sample-table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable": false, "aTargets": [0, 2, 3, 4, 5, 6]}// 制定列不参与排序
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
    });
</script>
